<template>
  <div class="login-container">
    <div class="login-form-wrap">
      <div class="login-head">
        <div class="logo"></div>
      </div>
      <el-form class="login-form" ref="form" :model="form">
        <el-form-item>
          <el-input v-model="form.mobile" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="form.code" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-checkbox v-model="form.isAgree" label="我已阅读并同意用户协议和隐私条款" name="type"></el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button class="login-btn" type="primary" @click="onSubmit">登陆</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data () {
    return {
      user: {
        mobile: '', // 手机号
        code: '' // 验证码
      },
      isAgree: false // 是否同意协议的选中状态
    }
  },
  methods: {
    onSubmit () {
    }
  },
  methods: {
    hLogin () {
      // 用户登陆
      // 1. 获取表单中的手机号 密码
      console.log(this.form.mobile, this.form.code, this.form.isAgree)
      // 2. 有效性检验
      // todo

      // 3. 向后端服务器发请求，带上参数
      // axios 就是填空题。答案在接口文档中
      axios({
        method: 'POST',
        url: 'http://ttapi.research.itcast.cn/mp/v1_0/authorizations',
        data: {
          mobile: this.form.mobile,
          code: this.form.code
        }
      }).then(res => {
        // 4. 根据返回结果：
        // （1）成功 -> 跳转
        console.log(res)
        alert('ok')
      }).catch(err => {
        //  (2) 失败 -> 提示
        console.log(err)
        alert('error')
      })
      console.log('submit!')
    }
  }
}
</script>
<style scoped lang="less">
// 铺满整屏
.login-container {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction:column;
  justify-content: center;
  align-items: center;
  background: url("../../assets/login_bg.jpg") no-repeat;
  background-size: cover;
  .login-form-wrap {
    min-width: 300px;
    padding: 30px 50px 10px;
    background-color: #fff;
    .login-head {
      display: flex;
      justify-content: center;
      .logo {
        width: 200px;
        height: 57px;
        background: url("../../assets/logo_index.png") no-repeat;
        background-size: contain;
      }
    }
    .login-form {
      .login-btn {
        width: 100%;
      }
    }
  }
}
</style>
